package com.sunyard.manage.controller;

import com.sunyard.dal.bo.operator.OperatorAuditBO;
import com.sunyard.dal.bo.operator.OperatorAuditChangeQueryBO;
import com.sunyard.dal.bo.operator.OperatorAuditQueryBO;
import com.sunyard.dal.bo.PaginationBO;
import com.sunyard.dal.dto.OperatorCopyDTO;
import com.sunyard.manage.service.OperatorAuditService;
import com.sunyard.utils.Response.BaseResult;
import com.sunyard.utils.Response.GetResult;
import com.sunyard.utils.manage.DataGrid;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import java.util.Map;

/**
 * @author jiy.fang
 * @ClassName OperatorAuditController
 * @Description description
 * @date 2019/7/24 10:09
 */
@Api(tags = "OperatorAuditController", description = "用户审核控制器")
@Slf4j
@RestController
@RequestMapping(value = "/operatorAudit", method = RequestMethod.POST)
public class OperatorAuditController {

    @Autowired
    private OperatorAuditService operatorAuditService;

    /**
     * @Description: 分页查询用户审核记录
     * @Author: jiy.fang
     * @Date: 2019/7/25 12:44
     */
    @ApiOperation("分页查询用户审核记录")
    @RequestMapping(value = "/showOperatorAudit")
    @ResponseBody
    public BaseResult<DataGrid<OperatorCopyDTO>> showOperatorAuditByPage(HttpServletRequest request, @Valid @RequestBody PaginationBO<OperatorAuditQueryBO> queryBO) throws Exception {
        DataGrid<OperatorCopyDTO> operatorCopyDTODataGrid = operatorAuditService.queryOperatorListAuditByPage(request, queryBO);
        return GetResult.getResult(operatorCopyDTODataGrid);
    }

    /**
     * @Description: 任务审核导出
     * @Author: tsz
     */
    @ApiOperation("用户审核导出")
    @RequestMapping(value = "/operatorAuditExport")
    @ResponseBody
    public void operatorAuditExport(HttpServletResponse response, @RequestBody OperatorAuditQueryBO operatorAuditQueryBO, HttpServletRequest request) {
        operatorAuditService.operatorAuditExport(response,operatorAuditQueryBO,request);
    }

    /**
     * @Description:用户审核
     * @Author: jiy.fang
     * @Date: 2019/7/25 12:44
     */
    @ApiOperation("用户审核")
    @RequestMapping(value = "/operatorAudit")
    @ResponseBody
    public BaseResult operatorAudit(HttpServletRequest request, @Valid @RequestBody OperatorAuditBO operatorAuditBO) throws Exception {
        return operatorAuditService.operatorAudit(request, operatorAuditBO);
    }

    /**
     * @Description: 批量用户审核
     * @Author: jiy.fang
     * @Date: 2019/7/25 12:44
     */
    @ApiOperation("批量用户审核")
    @RequestMapping(value = "/batchOperatorAudit")
    @ResponseBody
    public BaseResult batchOperatorAudit(HttpServletRequest request, @Valid @RequestBody OperatorAuditBO operatorAuditBO) throws Exception {
        return operatorAuditService.batchOperatorAudit(request, operatorAuditBO);
    }

    /**
     * @Description:
     * @Author: jiy.fang
     * @Date: 2019/8/2 18:08
     */
    @ApiOperation("根据审核编号查询审核前后的记录")
    @RequestMapping("/showRecordChange")
    public BaseResult<Map<Object, Object>> showRecordChange(@RequestBody OperatorAuditChangeQueryBO changeQueryBO) {
        Map<Object, Object> deviceVariety = operatorAuditService.queryOperatorRecordChange(changeQueryBO);
        return GetResult.getResult(deviceVariety);
    }

}
